﻿using AdminStystem.Domain;
using AdminSytem.Application.Dto;
using AdminSytem.Repositories;
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdminSytem.Application.Slaughters
{
    public class SlaughterServices : ISlaughterServices
    {
        private readonly IRepository<Slaughter> slaughterRepository;
        private readonly IRepository<SEnterprise> sEnterpriseRepository;
        private readonly IMapper mapper;

        public SlaughterServices(IRepository<Slaughter> slaughterRepository, IRepository<SEnterprise> sEnterpriseRepository, IMapper mapper)
        {
            this.slaughterRepository = slaughterRepository;
            this.mapper = mapper;
            this.sEnterpriseRepository = sEnterpriseRepository;
        }
        /// <summary>
        /// 添加屠宰信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ResultDto<int>> AddSlaughter(SlaughterDto dto)
        {
            ResultDto<int> result = new ResultDto<int>();
            result.StatusCode = StatusCode.Success;
            result.Message = "添加成功";
            var entity = mapper.Map<Slaughter>(dto);
            await slaughterRepository.InsertAsync(entity);
            return result;
        }
        /// <summary>
        /// 获取屠宰信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<ResultDto<Slaughter>> GetSlaughters(int id)
        {
            ResultDto<Slaughter> result = new ResultDto<Slaughter>();
            result.StatusCode = StatusCode.Success;
            result.Message = "查询成功";
            var list = await slaughterRepository.QueryFirstAsync(a => a.GoodsId == id);
            result.Data = list;
            return result;
        }
        /// <summary>
        /// 添加企业信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ResultDto<int>> AddSEnterprise(SEnterpriseDto dto)
        {
            ResultDto<int> result = new ResultDto<int>();
            result.StatusCode = StatusCode.Success;
            result.Message = "添加成功";
            var entity = mapper.Map<SEnterprise>(dto);
            await sEnterpriseRepository.InsertAsync(entity);
            return result;
        }
        /// <summary>
        /// 获取企业信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<ResultDto<SEnterprise>> GetSEnterprise(int id)
        {
            ResultDto<SEnterprise> result = new ResultDto<SEnterprise>();
            result.StatusCode = StatusCode.Success;
            result.Message = "查询成功";
            var list = await sEnterpriseRepository.QueryFirstAsync(a => a.GoodsId == id);
            result.Data = list;
            return result;
        }
    }
}
